import { instance } from "@/request"

class NoticeHttp {
  static BASE_URL = "http://localhost:3000/back"
  static getHttp({ url }) {
    return new Promise((resolve, reject) => {
      instance.get(this.BASE_URL + url).then((res) => {
        resolve(res)
      })
    })
  }
  static putHttp({ url }) {
    return new Promise((resolve, reject) => {
      instance.put(this.BASE_URL + url).then((res) => {
        resolve(res)
      })
    })
  }
  static postHttp({ url, param }) {
    return new Promise((resolve, reject) => {
      instance.post(this.BASE_URL + url, param).then((res) => {
        resolve(res)
      })
    })
  }
  /* 
    分页请求所有公告
   */
  static getPageNotice(page, size) {
    let mypage = page.value
    //console.log(mypage);
    //console.log(`/getallevent?page=${mypage}&size=${size}`);
    return this.getHttp({
      url: `/getallnotice?page=${mypage}&size=${size}`,
    })
  }
  /* 通过id查询某一条公告 */
  static getNoticeById(id) {
    return this.getHttp({
      url: `/getonenotice/${id}`,
    })
  }
  /* 将公告设置为已过期 */
  static passNotice(id) {
    return this.putHttp({
      url: `/notice/${id}`,
    })
  }
  /* 发布公告 */
  static publishNotice = (param) => {
    return this.postHttp({
      url: "/notice",
      param: param,
    })
  }
}
export { NoticeHttp }
